<template>
  <el-dialog :title="dataList.test" :visible.sync="dataList.type">
    <el-form :model="dataList">
      
      <el-form-item label="图标" :label-width="formLabelWidth">
        <el-upload
          class="avatar-uploader"
          action=""
          :show-file-list="false"
          :http-request="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
          style="width: 48px; height: 48px"
        >
          <img
            style="width: 48px; height: 48px"
            v-if="dataList.img"
            :src="dataList.img"
            class="avatar"
          />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>

      <el-form-item label="描述" :label-width="formLabelWidth">
        <el-input v-model="dataList.comment" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="跳转链接" :label-width="formLabelWidth">
        <el-input v-model="dataList.link" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="排序" :label-width="formLabelWidth">
        <el-input-number v-model="dataList.sort" controls-position="right" @change="handleChange" :min="1"></el-input-number>
      </el-form-item>

      <el-form-item label="状态" :label-width="formLabelWidth">
        <el-radio-group v-model="dataList.status">
          <el-radio :label="1">显示</el-radio>
          <el-radio :label="0">隐藏</el-radio>
        </el-radio-group>
    </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dataList.type = false">取 消</el-button>
      <el-button type="primary" @click="sure">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {MemberImage} from "../../api/dataallocation/NewProducts"
export default {
  props: ["dataList"],
  data() {
    return {
        formLabelWidth: "120px",
        imgs:""
    };
  },

  methods: {
      sure(){
          this.dataList.type=false
          console.log(this.dataList);
          if(this.dataList.id==""){
              this.$emit("add",this.dataList)
          }else{
              this.$emit("edit",this.dataList)
          }
      },
    handleAvatarSuccess(res, file) {
      let formdata = new FormData();
      formdata.append("pid", 0);
      formdata.append("file", this.imgs);
      MemberImage(formdata).then((res) => {
        if (res.data.status == 200) {
          this.$message({
            message: res.data.msg,
            type: "success",
          });
          this.dataList.img = "http://bw.gsruiying.com.cn/" + res.data.data.src;
        } else {
          this.$message({
            message: res.data.msg,
            type: "error",
          });
        }
      });
    },
    beforeAvatarUpload(file) {
      this.imgs = file;
    },
  },
};
</script>
<style lang='less' scoped>
</style>